home *** CD-ROM | disk | FTP | other *** search
- #include "stdafx.h"
-
- LPDIRECTDRAWSURFACE4 create_surface(int w, int h, DWORD caps, DWORD flags)
- {
- DDSURFACEDESC2 ddsd;
- LPDIRECTDRAWSURFACE4 dds = 0;
-
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | flags;
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | caps;
- ddsd.dwWidth = w;
- ddsd.dwHeight = h;
- ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = mask_color;
- ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = mask_color;
-
- DD->CreateSurface(&ddsd, &dds, 0);
-
- return dds;
- }
-
- void clear(LPDIRECTDRAWSURFACE4 buf, int color)
- {
- DDBLTFX ddbltfx;
-
- ddbltfx.dwSize = sizeof(ddbltfx);
- ddbltfx.dwFillColor = color;
-
- while (!draw_ok(buf->Blt(0, 0, 0, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx)));
- }
-
- int match_color(COLORREF rgb)
- {
- DDSURFACEDESC2 ddsd;
- HDC hdc;
- int c;
-
- // Use GDI SetPixel to do the color conversion
-
- if (FAILED(screen->GetDC(&hdc)))
- error("Unable to get device context for color match");
-
- SetPixel(hdc, 0, 0, rgb);
-
- screen->ReleaseDC(hdc);
-
- // Lock the surface for readback
-
- ddsd.dwSize = sizeof(ddsd);
-
- if (FAILED(screen->Lock(0, &ddsd, DDLOCK_WAIT, 0)))
- error("Unable to lock memory for color match");
-
- c = *(int *)ddsd.lpSurface;
-
- switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
- {
- case 8:
- c &= 0xff;
- break;
-
- case 16:
- c &= 0xffff;
- break;
-
- case 24:
- c &= 0xffffff;
- }
-
- screen->Unlock(0);
-
- return c;
- }
-
-